using SQLLog4net.Log;
// EA0908: Replace DMO lib by the SMO lib
// using SQLRunnerDMO;
using SQLRunnerLib.Project;
using SQLRunnerLib.Runners;
using SQLServices.Log;
using SQLServices.Repository;
using SQLServices.Runners;
using SQLServices.TransMgr;

namespace SQLRunnerLib.Services
{
	/// <summary>
	/// The Service Container provides global services to the application.
	/// The following global services are provided:
	/// Logger, SQLConnection and SQL Server finder
	/// </summary>
	public class ServiceContainer
	{

        private static ServiceContainer _serviceContainer;
		private IAppLogger _logger;
		private ISQLConnection _sqlConnection;
	    private ISQLServerFinder _sqlServerFinder;

        private ServiceContainer()
        {
        }

        public static ServiceContainer Instance
        {
            get
            {
                if (_serviceContainer == null)
                    _serviceContainer = new ServiceContainer();

                return _serviceContainer;
            }
        }
	    #region Services

		public IMessageLogger Logger
		{
			get
			{
                if (_logger == null)
                    _logger = new Logger();
                return _logger;
			}
		}

		public IEventLogger EventLogger
		{
			get
			{
                if (_logger == null)
                    _logger = new Logger();
                return _logger;
			}
		}

		public ISQLConnection SQLConnection
		{
			get
			{
                if (_sqlConnection == null)
                    _sqlConnection = new SQLRunnerSMO.SqlServerSmo();
                return _sqlConnection;
			}
        }

	    public ISQLServerFinder SQLServerFinder
	    {
	        get
	        {
                if (_sqlServerFinder == null)
                    _sqlServerFinder = new SQLRunnerSMO.Util();
                return _sqlServerFinder;
	        }
	    }

	    #endregion
        #region Helpers

        public static IPathItem CreatePathItem(string name, IPathItem prevNode)
		{
			return new PathItem(name, prevNode);
		}

        public static IRunner CreateRunner(SQLProject project, SQLEnvironment environment, ConnectionMgrType connectionManagerType)
		{
            return new Runner(project, environment, connectionManagerType);
        }

        #endregion

	}
}
